package com.atguigu.mr;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Project: DXXM
 * Package: com.atguigu
 * Version: 1.0
 * <p>
 * Created by  WangJX  on 2020/2/20 22:39
 */
public class CountDurationReducer extends Reducer<ComDimension, Text, ComDimension, CountDurationValue>{
    @Override
    protected void reduce(ComDimension key, Iterable<Text> values, Context context) throws IOException, InterruptedException {

        //通话次数
        int count = 0;
        //总通话时间
        int sumDuration = 0;
        for(Text text : values){
            count ++;
            sumDuration += Integer.valueOf(text.toString());
        }
        CountDurationValue countDurationValue = new CountDurationValue(count, sumDuration);
        context.write(key, countDurationValue);
    }
}
